from tkinter import *

def hello():
    print ("哎呦！")

tk = Tk()
##btn = Button(tk, text="点我",command=hello)
##btn.pack()

canvas=Canvas(tk,width=1000, height=800)
canvas.pack()
'''
canvas.create_line(0,0,500,500)

canvas.create_rectangle(10,10,110,110)
'''
#btn = Button(tk, text="点我",command=hello)
#btn.pack()

import random
import time
'''
def random_rectangle(width, height,fill_color):
    x1= random.randrange(width)
    y1= random.randrange(height)
    x2= random.randrange(x1+random.randrange(width))
    y2= random.randrange(y1+random.randrange(height))

    canvas.create_rectangle(x1,y1,x2,y2,fill=fill_color)
'''
#for x in range(0,100):
#    random_rectangle(400, 400)

color="#1fdfee"
#color = colorchooser.askcolor()   ##调色板
#random_rectangle(400, 400, color[1])

##canvas.create_arc(10,10,200, 100, extent=359, style=ARC)
##canvas.create_polygon(200,10, 240, 30, 120,100,140, 120, fill=color,outline="#ffef11")

canvas.create_text(200,200, text="游戏结束！", font=("Times",30))

''' #加载图片
my_image = PhotoImage(file="D:/Users/chen/Pictures/0.gif")

p1=canvas.create_image(0,0,anchor=NW, image=my_image)

while(True):
    canvas.move(p1,5,0)
    tk.update()
    time.sleep(0.1)
'''

#tri1 = canvas.create_polygon(10, 10, 10,60, 50,35,fill="#1fdfdf")
my_image= PhotoImage(file="D:/Users/chen/Pictures/0.gif")
tri1=canvas.create_image(0,0,anchor=NW, image=my_image)

def movetriangle(event):
    #direct="R"
    if(event.keysym =="Up") :
        canvas.move(tri1,0,-10)
    elif(event.keysym =="Right"):
        canvas.move(tri1,10,0)
    elif(event.keysym =="Left"):
        canvas.move(tri1,-10,0) 
    else:#Down
        canvas.move(tri1,0,10) 
    tk.update()
    
#canvas.bind_all("<KeyPress-Return>", movetriangle)
canvas.bind_all("<KeyPress>", movetriangle)


